package com.lottery.ruok.lottrey.common;

import android.app.Application;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ImageSpan;
import android.util.Log;
import android.util.SparseIntArray;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lottery.ruok.lottrey.BuildConfig;
import com.lottery.ruok.lottrey.MyApplication;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.bean.LotteryImageBean;
import com.lottery.ruok.lottrey.bean.XglhcColor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import ui.AreaCircle;
import ui.NoScrollGridView;
import utils.StringUtils;
import utils.Utils;

import static com.lottery.ruok.lottrey.bean.LotteryImageBean.DICE_LITTLE_SIZE;
import static com.lottery.ruok.lottrey.bean.LotteryImageBean.ICON_SIZE;
import static com.lottery.ruok.lottrey.bean.LotteryImageBean.LITTLE_DICE_MARGIN_TOP;

/**
 * Created by ASUS on 2017/7/26.
 */

public class Common {
    public static final String rsa_private_key = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKTsPxVFs46szp+1CqmzFAGvJ9Nx+CIG/F/9j8rk8zmmSay2/O1bME/s5h9aUU3UW/YkjGwJQtxkrVO9SzBOrGMyUm+A+kslL2tQf2f+RBYJCQv8GTydOFjc/7AR1Nfj/WYJglEyVJY/01+3T0Lb/cJSM7mvDfZs/wfFMbiOWGwtAgMBAAECgYBRO2v29lXyuHstfua5n1MDYVqkc0ZcvEQio6nnrc1/X8B6Kcd6waeSNoVCfCH/y9Ff87CWphkgpRYaYOpf6OBPUPnoB1Aa5tUJuoQjpCyl9OPI4d67tnzkwBa4t4iit+Dk4bYyqLXO+ra8co1uV/H3VVKeYcC/C1seNmwkZYZqAQJBANo1NKXU0IFlxzGroMe/tT+6SwztTfL4ExsuDUuiJdAy1oYJEbQq/7gXIS4yvkEWkCQIiXn02yhbHsLevXySUxECQQDBfIQgC+SqIfOvDeiE3oQtJ/Fsu2Z4kaWE8p7q/D34GcP2OJAj0DJYvaWPUGiljzQnHGBTz/LB/XtdONGwrk9dAkEAuxtMXbYyZAJl382PPDjCrjaMDDWf1Wuq1m+SrvwG+JPfJ2e3aopEZBJRPU/9m8pBJuS7HXw8QEqCAg8E5ECEQQJAIj/5X3bbfmZOLZGntEVzXk7wxI+TvwoBI7yS9wO5sH5XGvG+SiijkOPZN7pDG/Nyhu3V+2AXF9HYEZNqQv1IHQJAQ9klodKDDjS5gNnb7fxsSJ95+Hxt3Fz+bG3hqrqjzaVdSPUWbWYo8Jtu0zY8kmQaU5gg+hcj88w/68UftLlTzA==";
    public static final String CHAT_ACCOUNT = "admin@ruok.co";
    public static final String CHAT_PASSWORD = "ruok123";
    public static final String NO_SERVICE = "客服在忙，请稍等～";
    public static String APP_URL = String.format(BuildConfig.HOST_URL, MyApplication.UUID);
//    public static final String GET_STANDBY_URL = "https://lrgrmxx.com/apple/huobao_ops.json";
   // public static final String GET_STANDBY_URL = "https://lrgrmxx.com/apple/xintiandi.json" ;
    public static final String GET_STANDBY_URL = BuildConfig.GET_STANDBY_URL;


    //    public static final String LOTTERY_ANDROID_ACTION = "Lottery_Android_Action";
    public static String UserAgentString;
    public static XglhcColor xglhcColor = new XglhcColor();
    public static List<String> fobid_words;
    public static String today_profit = "0";
    public static String service_url = null;

    public static final String NO_NET = "请检查您的网络";
    public static final String IS_TEST = "试玩账号不能进行操作";
    public static final String NUM_PER_NOTE = "单注下单注数不能超过2000";
    public static final String NO_LOCATION = "定位失败，请检查是否允许获取地理位置";
    public static final String COPY_TIP = "已复制至剪贴板";
    // 充值通道 payType
    public static final String PAY_TYPE_MP = "MT";           //人工通道
    public static final String PAY_TYPE_WSP = "WSP004";      // 微信掃碼支付
    public static final String PAY_TYPE_ASP = "ASP005";      //支付寶掃碼支付
    public static final String PAY_TYPE_QQW = "QQW012";      //财付通扫码支付
    public static final String PAY_TYPE_UNP = "UNP014";      //银联支付
    public static final String PAY_TYPE_JCS = "JCS015";      //京东扫码支付
    public static final List<String> PL3_ALLIED = Arrays.asList("pl3","jspl3","fc3d","jsfc3d");
    private static Common INSTANCE;

    private Context context;

    private Common() {

    }

    public static Common getIns() {
        if (INSTANCE == null) {
            INSTANCE = new Common();
        }
        return INSTANCE;
    }

    public void init(Context context) {
        this.context = context;

        List<String> list1 = new ArrayList<>();
        list1.add("1");
        list1.add("2");
        list1.add("7");
        list1.add("8");
        list1.add("12");
        list1.add("13");
        list1.add("18");
        list1.add("19");
        list1.add("23");
        list1.add("24");
        list1.add("29");
        list1.add("30");
        list1.add("34");
        list1.add("35");
        list1.add("40");
        list1.add("45");
        list1.add("46");
        xglhcColor.setRed(list1);

        List<String> list2 = new ArrayList<>();
        list2.add("3");
        list2.add("4");
        list2.add("9");
        list2.add("10");
        list2.add("14");
        list2.add("15");
        list2.add("20");
        list2.add("25");
        list2.add("26");
        list2.add("31");
        list2.add("36");
        list2.add("37");
        list2.add("41");
        list2.add("42");
        list2.add("47");
        list2.add("48");
        xglhcColor.setBlue(list2);

        List<String> list3 = new ArrayList<>();
        list3.add("5");
        list3.add("6");
        list3.add("11");
        list3.add("16");
        list3.add("17");
        list3.add("21");
        list3.add("22");
        list3.add("27");
        list3.add("28");
        list3.add("32");
        list3.add("33");
        list3.add("38");
        list3.add("39");
        list3.add("43");
        list3.add("44");
        list3.add("49");
        xglhcColor.setGreen(list3);
    }

    public Context getContext() {
        return context;
    }

    /**
     * 根据值获取骰子图片
     * @param value
     * @return
     */
    public static int getDiceDrawable(int value){
        int drawable = R.drawable.shaizi1;
        switch (value){
            case 1:
                drawable = R.drawable.shaizi1;
                break;
            case 2:
                drawable = R.drawable.shaizi2;
                break;
            case 3:
                drawable = R.drawable.shaizi3;
                break;
            case 4:
                drawable = R.drawable.shaizi4;
                break;
            case 5:
                drawable = R.drawable.shaizi5;
                break;
            case 6:
                drawable = R.drawable.shaizi6;
                break;
        }
        return drawable;
    }

    public static void setGridAttributes(NoScrollGridView types,String code, String name){
        int columns = 3;
        int padding = 24;
        int paddingTop = 14;
        int horizontalSpacing = 18;
        int verticalSpacing = 12;
        if(isK3(code)){
            padding = 15;
            paddingTop = 20;
            horizontalSpacing = 10;
            verticalSpacing = 10;
            if("围骰全骰".equals(name)||"短牌".equals(name)||"长牌".equals(name)||"点数".equals(name)||"鱼虾蟹".equals(name)){
                columns = 2;
            }
        }
        types.setNumColumns(columns);
        types.setHorizontalSpacing(Utils.dip2px(MyApplication.getApplication(),horizontalSpacing));
        types.setVerticalSpacing(Utils.dip2px(MyApplication.getApplication(),verticalSpacing));
        padding = Utils.dip2px(MyApplication.getApplication(),padding);
        paddingTop = Utils.dip2px(MyApplication.getApplication(),paddingTop);
        types.setPadding(padding,paddingTop,padding,paddingTop);
    }





    /**
     * 传统快3和极速快3,幸运快3
     * @param code
     * @return
     */
    public static boolean isK3(String code){
        return "ctjiangsuk3".equals(code)||"ctshk3".equals(code)||"ctahk3".equals(code)||
                "cthebk3".equals(code)||"ctgxk3".equals(code)||"ctjxk3".equals(code)||
                "ctgsk3".equals(code)||"cthubk3".equals(code)||"ctjlk3".equals(code)||
                "jsk3".equals(code)||"jsxyk3".equals(code)||"js1fk3".equals(code);
    }

    /**
     *传统北京赛车,传统幸运飞艇和极速pk拾,极速飞艇
     * @param code
     * @return
     */
    public static boolean isRacing(String code){
        return "ctbjpk10".equals(code)||"ctxyft".equals(code)||
                "jsctpk10".equals(code)|| "jsctxyft".equals(code);
    }

    /**
     * 安徽快3和江苏快3  官方
     * @param code
     * @return
     */
    public static boolean isOfficialK3(String code){
        return "ahk3".equals(code)||"jiangsuk3".equals(code);
    }


    public static List<LotteryImageBean> getDrawableArray(String code, String name){
        List<LotteryImageBean> list = new ArrayList<>();
        if(isK3(code)){
            if(!TextUtils.isEmpty(name)){
                if(name.contains("三军")){
                    int value = StringUtils.parseInt(name.substring(2));
                    list.add(new LotteryImageBean(getDiceDrawable(value)));
                }else if(name.contains("围骰")){
                    int value = StringUtils.parseInt(name.substring(2));
                    list.add(new LotteryImageBean(getDiceDrawable(value)));
                    list.add(new LotteryImageBean(getDiceDrawable(value)));
                    list.add(new LotteryImageBean(getDiceDrawable(value)));
                }else if(name.contains("长牌")){
                    int value = StringUtils.parseInt(name.substring(2,3));
                    list.add(new LotteryImageBean(getDiceDrawable(value)));
                    value = StringUtils.parseInt(name.substring(3,4));
                    list.add(new LotteryImageBean(getDiceDrawable(value)));
                }else if(name.contains("短牌")){
                    int value = StringUtils.parseInt(name.substring(2));
                    list.add(new LotteryImageBean(getDiceDrawable(value)));
                    list.add(new LotteryImageBean(getDiceDrawable(value)));
                }else if("鱼".equals(name)){
                    list.add(new LotteryImageBean(getDiceDrawable(1),DICE_LITTLE_SIZE,DICE_LITTLE_SIZE,LITTLE_DICE_MARGIN_TOP));
                    list.add(new LotteryImageBean(R.drawable.icon_fish,0,ICON_SIZE));
                }else if("虾".equals(name)){
                    list.add(new LotteryImageBean(getDiceDrawable(2),DICE_LITTLE_SIZE,DICE_LITTLE_SIZE,LITTLE_DICE_MARGIN_TOP));
                    list.add(new LotteryImageBean(R.drawable.icon_shrimp,0,ICON_SIZE));
                }else if("葫芦".equals(name)){
                    list.add(new LotteryImageBean(getDiceDrawable(3),DICE_LITTLE_SIZE,DICE_LITTLE_SIZE,LITTLE_DICE_MARGIN_TOP));
                    list.add(new LotteryImageBean(R.drawable.icon_gourd,0,ICON_SIZE));
                }else if("金钱".equals(name)){
                    list.add(new LotteryImageBean(getDiceDrawable(4),DICE_LITTLE_SIZE,DICE_LITTLE_SIZE,LITTLE_DICE_MARGIN_TOP));
                    list.add(new LotteryImageBean(R.drawable.icon_money,0,ICON_SIZE));
                }else if("蟹".equals(name)){
                    list.add(new LotteryImageBean(getDiceDrawable(5),DICE_LITTLE_SIZE,DICE_LITTLE_SIZE,LITTLE_DICE_MARGIN_TOP));
                    list.add(new LotteryImageBean(R.drawable.icon_crab,0,ICON_SIZE));
                }else if("鸡".equals(name)){
                    list.add(new LotteryImageBean(getDiceDrawable(6),DICE_LITTLE_SIZE,DICE_LITTLE_SIZE,LITTLE_DICE_MARGIN_TOP));
                    list.add(new LotteryImageBean(R.drawable.icon_chicken,0,ICON_SIZE));
                }
            }
        }
        return list;
    }



    public static void setBallBackground(AreaCircle areaCircle, String s,String code){
        if(s != null && !s.equals("")) {
//            if (s.equals("0")) {
//                areaCircle.setBackground(Color.parseColor("#de625c"));
//            } else {
                if(Utils.isNumeric(s)){
                    int num = Integer.parseInt(s);
                    switch (num % 10) {
                        case 0:
                            // 特定的彩种
                            if ("bjpk10".equals(code) || "ctbjpk10".equals(code) || "jsctpk10".equals(code) || "jsctxyft".equals(code) || "ctxyft".equals(code)) {
                                areaCircle.setBackground(Color.parseColor("#34C123"));
                            } else {
                                areaCircle.setBackground(Color.parseColor("#4DB40B"));
                            }
                            break;
                        case 1:
                            if ("bjpk10".equals(code) || "ctbjpk10".equals(code) || "jsctpk10".equals(code) || "jsctxyft".equals(code) || "ctxyft".equals(code)) {
                                areaCircle.setBackground(Color.parseColor("#E6D241"));
                            } else {
                                areaCircle.setBackground(Color.parseColor("#EC282A"));
                            }
                            break;
                        case 2:
                            if ("bjpk10".equals(code) || "ctbjpk10".equals(code) || "jsctpk10".equals(code) || "jsctxyft".equals(code) || "ctxyft".equals(code)) {
                                areaCircle.setBackground(Color.parseColor("#198EFD"));
                            } else {
                                areaCircle.setBackground(Color.parseColor("#E69605"));
                            }
                            break;
                        case 3:
                            if ("bjpk10".equals(code) || "ctbjpk10".equals(code) || "jsctpk10".equals(code) || "jsctxyft".equals(code) || "ctxyft".equals(code)) {
                                areaCircle.setBackground(Color.parseColor("#4E4E4E"));
                            } else {
                                areaCircle.setBackground(Color.parseColor("#3180C2"));
                            }
                            break;
                        case 4:
                            if ("bjpk10".equals(code) || "ctbjpk10".equals(code) || "jsctpk10".equals(code) || "jsctxyft".equals(code) || "ctxyft".equals(code)) {
                                areaCircle.setBackground(Color.parseColor("#FD7324"));
                            } else {
                                areaCircle.setBackground(Color.parseColor("#BF33B7"));
                            }
                            break;
                        case 5:
                            if ("bjpk10".equals(code) || "ctbjpk10".equals(code) || "jsctpk10".equals(code) || "jsctxyft".equals(code) || "ctxyft".equals(code)) {
                                areaCircle.setBackground(Color.parseColor("#1EB9B9"));
                            } else {
                                areaCircle.setBackground(Color.parseColor("#019EB4"));
                            }
                            break;
                        case 6:
                            if ("bjpk10".equals(code) || "ctbjpk10".equals(code) || "jsctpk10".equals(code) || "jsctxyft".equals(code) || "ctxyft".equals(code)) {
                                areaCircle.setBackground(Color.parseColor("#5525FB"));
                            } else {
                                areaCircle.setBackground(Color.parseColor("#EC2A6C"));
                            }
                            break;
                        case 7:
                            if ("bjpk10".equals(code) || "ctbjpk10".equals(code) || "jsctpk10".equals(code) || "jsctxyft".equals(code) || "ctxyft".equals(code)) {
                                areaCircle.setBackground(Color.parseColor("#B8B8B8"));
                            } else {
                                areaCircle.setBackground(Color.parseColor("#6061EB"));
                            }
                            break;
                        case 8:
                            if ("bjpk10".equals(code) || "ctbjpk10".equals(code) || "jsctpk10".equals(code) || "jsctxyft".equals(code) || "ctxyft".equals(code)) {
                                areaCircle.setBackground(Color.parseColor("#FC0E1B"));
                            } else {
                                areaCircle.setBackground(Color.parseColor("#ED6520"));
                            }
                            break;
                        case 9:
                            if ("bjpk10".equals(code) || "ctbjpk10".equals(code) || "jsctpk10".equals(code) || "jsctxyft".equals(code) || "ctxyft".equals(code)) {
                                areaCircle.setBackground(Color.parseColor("#760208"));
                            } else {
                                areaCircle.setBackground(Color.parseColor("#8653DC"));
                            }
                            break;
                    }
                } else {
                    areaCircle.setBackground(Color.parseColor("#de625c"));
                }

//            }
        } else {
            areaCircle.setBackground(Color.parseColor("#de625c"));
        }
    }
}
